#include <math.h>
#include <iostream>

using std::cout;
using std::endl;

class Point {
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int,int)" << endl;
    }

    void print() const
    {
        cout << "(" << _ix 
             << "," << _iy
             << ")" << endl;
    }

    //声明为友元
    friend double distance(const Point & lhs, const Point &rhs);
    
private:
    int _ix;
    int _iy;
};


//普通函数
double distance(const Point & lhs, const Point & rhs)
{
    return sqrt((lhs._ix - rhs._ix) * (lhs._ix - rhs._ix)  + 
                (lhs._iy - rhs._iy) * (lhs._iy - rhs._iy));
}

int main()
{
    Point pt1(1, 2), pt2(3, 4);
    pt1.print(); 
    cout << " ---> ";
    pt2.print();
    cout << "的距离是:" << distance(pt1, pt2);
    cout << endl;

    return 0;
}

